package com.spsoft.vatoutinv.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.spsoft.core.annotation.AnonymousAccess;
import com.spsoft.core.annotation.Log;
import com.spsoft.core.controller.BaseController;
import com.spsoft.core.enums.LogActionType;
import com.spsoft.core.enums.LogMenuEnum;
import com.spsoft.core.model.Result;
import com.spsoft.vatoutinv.model.dto.vmshzqrdmanage.VmsFsfpxzHzqrdPageDto;
import com.spsoft.vatoutinv.model.dto.vmsissuenegativeinvoices.InvoiceDto;
import com.spsoft.vatoutinv.model.dto.vmsissuenegativeinvoices.RedConfirmationFormDto;
import com.spsoft.vatoutinv.model.vo.vmshzqrdmanage.VmsLeqiHzqrdVo;
import com.spsoft.vatoutinv.model.vo.vmsissuenegativeincoices.RedConfirmationFormVo;
import com.spsoft.vatoutinv.model.vo.vmsissuenegativeincoices.manual.VmsApprovalHzqrdManualVo;
import com.spsoft.vatoutinv.service.vmshzqrdmanage.VmsLeqiHzqrdService;
import com.spsoft.vatoutinv.service.vmsissuenegativeinvoices.VmsIssueNegativeInvoicesService;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangy
 * @date 2024/1/22 9:21
 */
@Api(tags = {"手工开具负数发票"})
@Validated
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/vmsIssueNegativeInvoices")
public class VmsIssueNegativeInvoicesController extends BaseController {

    public static final String LOG_MSG = "手工开具负数发票";

    private final VmsIssueNegativeInvoicesService issueNegativeInvoicesService;

    private final VmsLeqiHzqrdService vmsLeqiHzqrdService;

    @ApiOperation("手工开具负数发票-查询已开发票中负数发票")
    @AnonymousAccess(value = "/page", method = RequestMethod.POST, permissionCode = "VMS_KJFSFP")
    @Log(value = "手工开具负数发票-查询已开发票中负数发票", type = LogActionType.SELECT, menuName = LogMenuEnum.MANUALLY_ISSUING_NEGATIVE_INVOICES)
    public Result<IPage<RedConfirmationFormVo>> page(@RequestBody RedConfirmationFormDto dto) {
        log.info("{}手工开具负数发票-查询已开发票中负数发票,红字确认单编号：{}", LOG_MSG, JSONObject.toJSONString(dto));
        return issueNegativeInvoicesService.redConfirmationForm(dto);
    }

    @ApiOperation("手工开具负数发票-根据红字确认单查询发票信息")
    @AnonymousAccess(value = "/getInfoByRedNo", method = RequestMethod.POST, permissionCode = "VMS_FULL_ISSUE_NEGATIVE_INVOICE")
    @Log(value = "手工开具负数发票-根据红字确认单查询发票信息", type = LogActionType.SELECT, menuName = LogMenuEnum.MANUALLY_ISSUING_NEGATIVE_INVOICES)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hzfpxxqrdbh", value = "红字确认单编号", dataTypeClass = String.class, dataType = "String", required = true),
    })
    public Result<VmsApprovalHzqrdManualVo> getInfoByRedNo(@RequestParam(value = "hzfpxxqrdbh") String hzfpxxqrdbh) {
        log.info("{}调用手工开具负数发票-根据红字确认单查询发票信息,红字确认单编号：{}", LOG_MSG, hzfpxxqrdbh);
        return issueNegativeInvoicesService.getInfoByRedNo(hzfpxxqrdbh);
    }

    @ApiOperation("手工开具负数发票-选择红字确认单列表查询")
    @AnonymousAccess(value = "/redPage", method = RequestMethod.POST, permissionCode = "VMS_FULL_ISSUE_NEGATIVE_INVOICE")
    @Log(value = "手工开具负数发票-选择红字确认单列表查询", type = LogActionType.SELECT, menuName = LogMenuEnum.MANUALLY_ISSUING_NEGATIVE_INVOICES)
    public Result<IPage<VmsLeqiHzqrdVo>> redPage(@RequestBody VmsFsfpxzHzqrdPageDto dto) {
        log.info("{}手工开具负数发票-选择红字确认单列表查询,查询参数：{}", LOG_MSG, JSONObject.toJSONString(dto));
        return vmsLeqiHzqrdService.pageHzqrd(dto);
    }

    @ApiOperation("手工开具负数发票-开票")
    @AnonymousAccess(value = "/invoice", method = RequestMethod.POST, permissionCode = "VMS_FULL_ISSUE_NEGATIVE_INVOICE")
    @Log(value = "手工开具负数发票-开票", type = LogActionType.SELECT, menuName = LogMenuEnum.MANUALLY_ISSUING_NEGATIVE_INVOICES)
    public Result<Object> invoice(@RequestBody InvoiceDto dto) {
        log.info("{}调用手工开具负数发票-开票，入参：{}", LOG_MSG, JSONObject.toJSONString(dto));
        return issueNegativeInvoicesService.invoice(dto.getHzfpxxqrdbh(), dto.getBz());
    }

    @ApiOperation("手工开具负数发票-校验状态")
    @AnonymousAccess(value = "/checkStatus", method = RequestMethod.POST, permissionCode = "VMS_FULL_ISSUE_NEGATIVE_INVOICE")
    @Log(value = "手工开具负数发票-校验状态", type = LogActionType.SELECT, menuName = LogMenuEnum.MANUALLY_ISSUING_NEGATIVE_INVOICES)
    public Result<Object> checkStatus() {
        return issueNegativeInvoicesService.checkStatus();
    }

}